import { stringHash } from './utils'
export default class Vehicle {
  /** 从模型数组中获取对应模型 */
  static fromInfo(vClassObjects, vehicleId, info) {
    const objects = vClassObjects[info.vClass];
    if (!objects) {
      console.warn(`Unsupported vehicle type: ${info.vClass}`);
      return null;
    }
    const randomModelIndex = stringHash(vehicleId) % objects.length;
    const vehicleObj = objects[randomModelIndex];
    const mesh = vehicleObj.clone();
    
    return new Vehicle(mesh, vehicleId, info);
  }
  constructor(mesh, vehicleId, info) {
    mesh.name = vehicleId;
    mesh.userData = {
      type: info.type,
      vClass: info.vClass,
    };

    this.vehicleInfo = info;
    this.mesh = mesh;
    return this;
  }
}